package com.raos.config;

import org.springframework.context.annotation.Configuration;

/**
 * kafka入门之 springboot-kafka配置
 *
 * @author raos
 * @emil 991207823@qq.com
 * @date 2021/6/20 20:55
 */
@Configuration
public class KafkaConfig {
//    @Value("${spring.kafka.bootstrap-servers}")
//    private String servers;
//    @Value("${spring.kafka.producer.retries}")
//    private int retries;
//    @Value("${spring.kafka.producer.acks}")
//    private String acks;
//    @Value("${spring.kafka.producer.batch-size}")
//    private int batchSize;
//    @Value("${spring.kafka.producer.properties.linger.ms}")
//    private int linger;
//    @Value("${spring.kafka.producer.buffer-memory}")
//    private int bufferMemory;
//
//
//    public Map<String, Object> producerConfigs() {
//        Map<String, Object> props = new HashMap<>();
//        props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, servers);
//        props.put(ProducerConfig.RETRIES_CONFIG, retries);
//        props.put(ProducerConfig.ACKS_CONFIG, acks);
//        props.put(ProducerConfig.BATCH_SIZE_CONFIG, batchSize);
//        props.put(ProducerConfig.LINGER_MS_CONFIG, linger);
//        props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, bufferMemory);
//        props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
//        props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
//        return props;
//    }
//
//    @Bean
//    public ProducerFactory<String, Object> producerFactory() {
//        DefaultKafkaProducerFactory factory = new DefaultKafkaProducerFactory<>(producerConfigs());
//        factory.transactionCapable();
//        factory.setTransactionIdPrefix("tran-");
//        return factory;
//    }
//
//    @Bean
//    public KafkaTemplate<String, Object> kafkaTemplate(){
//        return new KafkaTemplate<>(producerFactory());
//    }
//
//    @Bean
//    public KafkaTransactionManager transactionManager() {
//        KafkaTransactionManager manager = new KafkaTransactionManager(producerFactory());
//        return manager;
//    }
}
